﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace QuanlyThoiGian
{
    public partial class FormBaoCaoSoSanh : Form
    {
        public FormBaoCaoSoSanh()
        {
            InitializeComponent();
        }

        private void xembutton_Click(object sender, EventArgs e)
        {
            DateTime thang1 = thang1dateTimePicker.Value;
            DateTime thang2 = thang2dateTimePicker.Value;
            DateTime cur = DateTime.Today;

            if (thang1 >= thang2 || thang1 >= cur || thang2 >= cur)
            {
                MessageBox.Show("Vui lòng nhập lại hai tháng !");
                return;
            }

            DateTime ngaybd1 = new DateTime(thang1.Year, thang1.Month, 1);
            DateTime ngaykt1 = new DateTime(thang1.Year, thang1.Month, DateTime.DaysInMonth(thang1.Year, thang1.Month));

            DateTime ngaybd2 = new DateTime(thang2.Year, thang2.Month, 1);
            DateTime ngaykt2 = new DateTime(thang2.Year, thang2.Month, DateTime.DaysInMonth(thang2.Year, thang2.Month));
            try
            {
                this.baocaososanhTableAdapter1.Fill(quanLyThoiGianDataSet1.baocaososanh, ngaybd1.ToShortDateString(),ngaykt1.ToShortDateString(), ngaybd2.ToShortDateString(), ngaykt2.ToShortDateString());
                crystalReportViewer1.ReportSource = crystalReportBaoCaoSoSanh1;
                crystalReportBaoCaoSoSanh1.SetDataSource(quanLyThoiGianDataSet1);
                crystalReportBaoCaoSoSanh1.Refresh();
            }
            catch (SqlException) { } 
        }
    }
}
